package com.dididoctor.doctor.Activity.PatientDetial;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dididoctor.doctor.Adapter.PictureGridViewAdapter;
import com.dididoctor.doctor.Bean.ImageInfo;
import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Ui.TagsGridView;
import com.dididoctor.doctor.Utils.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by boy on 2016/4/21.
 */
public class CaseHistoryDetialActivity extends EduActivity implements CasesHistoryDetailView {
    private TextView mTvHospital, mTvDateTime, mTvDoctorname, mTvJibing, mTvResult;
    private TextView mTvTitle;
    private ImageView mBtnBack;

    private CasesDetailDialogAdapter dialogadapter;
    private List<QuslistBean> quslists = new ArrayList<>();
    private ListView mLvDialog;

    private CasesHistoryDetailPresenter presenter;
    private String recId = "", type = "";

    //医生建议
    private TextView mTvSurvey, mTvMedicine, mTvSee, mTvOther;
    private LinearLayout mLlSurvey, mLlMedicine, mLlSee, mLlOther, mLlEvaluat, mllInquirye, mLlRelatedPictre;

    private TagsGridView mGvImage;
    private ReplyImageAdapter adapter;
    private RelativeLayout mRldialog;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_casehistory_detail);
        recId = getIntent().getStringExtra("recId");
        type = getIntent().getStringExtra("type");
    }

    @Override
    public void init() {
        /**头部**/
        initTitleView();

        initView();

        initData();

    }

    private void initData() {

        dialogadapter = new CasesDetailDialogAdapter(this, quslists);
        mLvDialog.setAdapter(dialogadapter);

        recId = getIntent().getStringExtra("recId");
        presenter = new CasesHistoryDetailPresenter(this, this);
        presenter.lunch(recId);

        this.adapter = new ReplyImageAdapter(this);
        mGvImage.setAdapter(adapter);
    }

    private void initView() {
        mTvHospital = (TextView) findViewById(R.id.tv_hospital);
        mTvDateTime = (TextView) findViewById(R.id.tv_date_time);
        mTvDoctorname = (TextView) findViewById(R.id.tv_doctorname);
        mTvJibing = (TextView) findViewById(R.id.tv_jibing);
        mTvResult = (TextView) findViewById(R.id.tv_result);

        mLvDialog = (ListView) findViewById(R.id.dialog_listview);

        //医生建议
        mTvSurvey = (TextView) findViewById(R.id.tv_survey);
        mTvMedicine = (TextView) findViewById(R.id.tv_medicine);
        mTvSee = (TextView) findViewById(R.id.tv_see);
        mTvOther = (TextView) findViewById(R.id.tv_other);
        mLlSurvey = (LinearLayout) findViewById(R.id.ll_survey);
        mLlMedicine = (LinearLayout) findViewById(R.id.ll_medicine);
        mLlSee = (LinearLayout) findViewById(R.id.ll_see);
        mLlOther = (LinearLayout) findViewById(R.id.ll_other);

        //問診表
        mllInquirye = (LinearLayout) findViewById(R.id.ll_inquiry);
        mllInquirye.setOnClickListener(this);
        //相关图片
        mGvImage = (TagsGridView) findViewById(R.id.gv_image);
        mLlRelatedPictre = (LinearLayout) findViewById(R.id.ll_related_pictre);
        mRldialog = (RelativeLayout) findViewById(R.id.rl_dialog);
        findViewById(R.id.img_cancel).setOnClickListener(this);
        if ("2".equals(type)) {
            mLlRelatedPictre.setVisibility(View.VISIBLE);
        } else {
            mLlRelatedPictre.setVisibility(View.GONE);
        }

        if ("1".equals(type)) {
            mllInquirye.setVisibility(View.VISIBLE);
        } else {
            mllInquirye.setVisibility(View.GONE);
        }

    }

    private void initTitleView() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvTitle.setText("病历详情");
        mBtnBack = (ImageView) findViewById(R.id.btn_back);
    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.ll_inquiry:
                mRldialog.setVisibility(View.VISIBLE);
                break;
            case R.id.img_cancel:
                mRldialog.setVisibility(View.GONE);
                break;
            case R.id.rl_dialog:
                break;
        }

    }


    @Override
    public void getcasesdetail(CasesHistoryDetailBean casesDetail, List<QuslistBean> quslists, List<AdviceBean> advices, List<ImageInfo> images) {
        if (casesDetail != null) {
            mTvHospital.setText(casesDetail.getHosName());
            mTvDateTime.setText(casesDetail.getClinicDate());
            mTvDoctorname.setText(casesDetail.getDctName());
            mTvJibing.setText(casesDetail.getDescr());
            mTvResult.setText(casesDetail.getResult());
        }

        if (!Util.isEmpty(quslists)) {
            this.quslists.clear();
            this.quslists = quslists;
            dialogadapter.addData(this.quslists);
            dialogadapter.notifyDataSetChanged();
        }
        if (!Util.isEmpty(advices)) {
            for (int i = 0; i < advices.size(); i++) {
                AdviceBean advice = advices.get(i);
                if ("1".equals(advice.getType())) {
                    mLlSurvey.setVisibility(View.VISIBLE);
                    mLlMedicine.setVisibility(View.GONE);
                    mLlSee.setVisibility(View.GONE);
                    mLlOther.setVisibility(View.GONE);
                    mTvSurvey.setText(advice.getContent());
                } else if ("2".equals(advice.getType())) {
                    mLlSurvey.setVisibility(View.GONE);
                    mLlMedicine.setVisibility(View.GONE);
                    mLlSee.setVisibility(View.VISIBLE);
                    mLlOther.setVisibility(View.GONE);
                    mTvSee.setText(advice.getContent());
                } else if ("3".equals(advice.getType())) {
                    mLlSurvey.setVisibility(View.GONE);
                    mLlMedicine.setVisibility(View.VISIBLE);
                    mLlSee.setVisibility(View.GONE);
                    mLlOther.setVisibility(View.GONE);
                    mTvMedicine.setText(advice.getContent());
                } else if ("4".equals(advice.getType())) {
                    mLlSurvey.setVisibility(View.GONE);
                    mLlMedicine.setVisibility(View.GONE);
                    mLlSee.setVisibility(View.GONE);
                    mLlOther.setVisibility(View.VISIBLE);
                    mTvOther.setText(advice.getContent());
                }
            }
        }

        this.adapter.addData(images);
    }

    @Override
    public void getcasesdetailfail() {

    }

    class ReplyImageAdapter extends PictureGridViewAdapter {

        public ReplyImageAdapter(Context context) {
            super(context);
        }

        @Override
        protected void handleExistImage() {

        }

        @Override
        protected void addImage() {

        }

        @Override
        protected void delectImage(ImageInfo item, int position) {

        }
    }

}
